#include <vector>
#include<set>
class Solution {
public:
    std::vector<std::vector<int>> res;
    int len = 0;
    std::vector<std::vector<int>>  permuteUnique(std::vector<int>& nums) {
        len = nums.size();
        cal(nums,0);
        return res;
    }
    void  cal(std::vector<int> nums,int index)
    {
        if (index ==len)
        {
            make(nums);
            return;
        }
std::set<int> ss;
        for (int i=index ;i<len;i++)
        {
            if (ss.find(nums[i])!=ss.end()) continue;
            swap(nums,index,i);
            cal(nums,index+1);
            swap(nums,i,index);
            ss.insert(nums[i]);
        }
        
    }
    void make(const std::vector<int>& cur)
    {
        std::vector<int> now ;
        for (int value : cur)
        {
            now.push_back(value);
        }
        res.push_back(now);
    }
    void swap(std::vector<int> &nums,int i,int j )
    {
        int d = nums[i];
        nums[i] = nums[j];
        nums[j] = d;
    }
};
